ad.gol          	      package:adGol        		        R Documentation

Simulation of the Game of Life

Description:

	A function that simulates the game of life given a binary matrix (cellular tissue) which may or may not exhibit graphical and textual display.

Usage:

	ad.gol(mat)

	## Default method:
	ad.gol(mat = ad.stable, thres.min = 3, thres.max = 3, min = 2, max = 3, it = 100, p.act = -1, p.deact = -1, graphics = TRUE, text = FALSE, sl = 2, SLEEP = ad.sleep.gc)

Arguments:

	mat:  a binary matrix with elements 0 and 1 which is the initial state of a cellular tissue in which cells may be active or inactive. The dimensions of the matrix must be strictly positive.

	thres.min:  the minimum value of active neighbours necessary to activate an inactive cell, which means turn a 0 into a 1. The values of this variable must range from 0 to 8. Decimal values are ceiled.

	thres.max:  the maximum value of active neighbours necessary to activate an inactive cell, which means turn a 0 into a 1. The values of this variable must range from 0 to 8. Decimal values are ceiled.

	min:  the minimum value of active neighbours necessary to deactivate an active cell, which means turn a 1 into a 0. The values of this variable must range from 0 to 8. Decimal values are ceiled.

	max:  the maximum value of active neighbours necessary to deactivate an active cell, which means turn a 1 into a 0. The values of this variable must range from 0 to 8. Decimal values are ceiled.

	it: the desired number of iterations on the simulation.

	p.act:  the probability of activation of a currently inactive cell. The usual numbers range from 0 to 1, but negative numbers are treated the same as zero.

	p.deact:  the probability of deactivation of a currently active cell. The usual numbers range from 0 to 1, but negative numbers are treated the same as zero.

	graphics:  boolean option for graphical display of the simulation.

	text:  boolean option for textual display of the simultion.

	sl:  the number of seconds each frame is to be displayed after renderization, which may be decimal. Sleep time. This parameter will be passed to the function SLEEP. If this variable is set to zero there will be no break for visualization.

	SLEEP:  the sleep function to be called after each frame renderization. The adGol package offers two options: ad.sleep() and ad.sleep.gc(). If this variable is set to NULL there will be no break for visualization.

Value:

	The object returned by ad.gol is a binary bidimensional matrix with the same dimensions as the one provided in the function call. This matrix corresponds to the final state of the cellular tissue after the specified number of iterations.

	When non-expected values are passed to the function, it may return the string "ERROR".

Warning:

	For matrixes of high dimensions, the renderization takes quite an amount of time, which is not a bug nor a problem with your computer.

Author(s):

	Ademar Marques Lacerda Filho

See Also:

	'ad.gol.draw', 'ad.sleep', 'ad.sleep.gc', 'ad.end'.

References:

	Wikipedia: http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Examples:
	
	# A simulation of some stable patterns
	ad.gol(ad.stable)

	# A simulation that yields facial patterns
	ad.gol(ad.faces, it = 20)

	# A simulation that yields radial patterns
	ad.gol(radial, it = 50)

	# Another example of radial patterns
	ad.gol(ad.one, thres.min = 1, thres.max = 1, min = 3, max = 4, it = 20)

	# A simulation of a single layer of initially active cells with a diferent set of rules and a greater speed of simulation
	x = matrix(1, 1, 20)
	ad.gol(x, thres.min = 1, thres.max = 2, min = 1, max = 1, sl = 0.4)

	# A stochastic simulation in which all cells are initially active and they are governed *mostly* by chance
	ad.gol(ad.one, thres.min = 8, thres.max = 8, min = 0, max = 8, p.act = 0.3, p.deact = 0.3)

	# This code plots the last matrix of a simulation of 1000 iterations that starts with a random matrix, this is a great way of finding patterns for any set of rules
	x = ad.gol(ad.random, thres.min = 2, thres.max = 4, min = 3, max = 6, it = 1000, graphics = FALSE)
	x11(bg = "grey")
	ad.gol.draw(x)
